package com.cac.demo.util;

import com.cac.demo.controller.CallInterFace.SendMaterialInterface;
import com.cac.demo.dao.materialReceive.WmsItemInventoryDao;
import com.cac.demo.dao.msWorkbinMaterial.MsWorkbinMaterialDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
@Slf4j
public class MaterialReceiptUtil {
    @Autowired
    private MsWorkbinMaterialDao msWorkbinMaterialDao;
    @Autowired
    private SendMaterialInterface sendMaterialInterface;
    @Autowired
    private WmsItemInventoryDao wmsItemInventoryDao;
    @Value("${pathProperty.isTest}")
    private boolean isTest;

    public List<HashMap> comparePackAo(HashMap map) {
        List<HashMap> samePackageList = new ArrayList<>();
        //1：获取工作包下的AO是否一致
        List<HashMap> packageList = msWorkbinMaterialDao.querySatisPackageList(map);
        if (packageList.size() == 0) {
            return samePackageList;
        }
        //2:对比工作包下的AO是否一致
        for (HashMap pack : packageList) {
            boolean materialIsSame = true;
            List<HashMap> aoList = msWorkbinMaterialDao.querySatisAoList((String) map.get("msTaskPackageId"), (String) pack.get("msTaskPackageId"));
            if (aoList.size() == 0) {//查询出来没数据说明该工作包与选择的工作包AO一致
                //3:对比工作包下AO对应的物料清单是否一致
                //3-1:查询该工作包下的AO，遍历AO
                List<HashMap> materialList = msWorkbinMaterialDao.querySatisMaterialList((String) map.get("msTaskPackageId"), (String) pack.get("msTaskPackageId"));
                if (materialList.size() == 0) {//查询出来为空说明 该工作包下所有的物料均一致
                    samePackageList.add(pack);
                }
            }
        }
        return samePackageList;
    }

    //分拣上传MES分拣状态7-24-lqc
    public void SendSortingMsgToMES() {
        HashMap paramMap = new HashMap();
//        if(isTest){
//            paramMap.put("dmsCode", "ms_fjztsccs");
//        }else {
//            paramMap.put("dmsCode", "ms_fjztsc");
//        }
        paramMap.put("dmsCode", "ms_fjztsc");
        paramMap.put("is_sort", "N");
        HashMap interfaceMap = new HashMap();
        interfaceMap.put("code", "getMatchData");
        interfaceMap.put("name", "获取数据配套场景的配套数据");
        interfaceMap.put("parameters", paramMap);
        interfaceMap.put("func", "101-MES-MaterialState");
        interfaceMap.put("sendScenario", "分拣状态上传MES");
        try {
            sendMaterialInterface.SendFileInterface(interfaceMap);
        } catch (Exception e) {
            log.info("****分拣保存上传MES分拣状态程序异常！");
            e.printStackTrace();
            log.info("****分拣保存上传MES分拣状态异常！");
        }
    }

    //漏扫物料按钮 lqc10-30
    public String repairMaterial(String workbinCode) {
        log.info("00000000000"+workbinCode);
        int rsl = wmsItemInventoryDao.updateWmsDeliveryPlanStatus(workbinCode);
        if (rsl > 0) {
            return "200";
        } else {
            return "201";
        }
    }

}
